package com.htht.smartschool.service.student;

import java.io.File;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.htht.smartschool.common.service.BaseService;
import com.htht.smartschool.model.card.TBdworkhour;
import com.htht.smartschool.model.card.TCard;
import com.htht.smartschool.model.common.TUserStudent;
import com.htht.smartschool.model.student.StudentCard;
import com.htht.smartschool.model.student.TStudent;
import com.htht.smartschool.model.teacher.TClass;
import com.htht.smartschool.model.user.TUser;
import com.htht.smartschool.service.user.UserService;
import com.htht.smartschool.util.system.ConfigUtil;
import com.htht.smartschool.util.system.DateUtil;
import com.htht.smartschool.util.system.EncryptUtil;
import com.htht.smartschool.util.system.ImgUtil;
import com.htht.smartschool.util.system.ResultSetToExcel;

public class StudentService extends BaseService {
	private Map addPeriodMap = new HashMap() ;
	/**
	 * 添加学生信息
	 * 
	 * @param tstudent
	 * @return
	 */
	public TStudent add(TStudent tstudent) {
		TStudent student = getUserDetail(tstudent.getStudentcode(),
				tstudent.getSchoolcode());
		String usertype = student.getStudytype();
		if (student != null && usertype == tstudent.getStudytype()) {
			return null;
		} else {
			if (student.getHeadimg() != null
					&& student.getHeadimg().length() > 0) {
				ImgUtil.remove(
						ImgUtil.usersimgpath + "/" + tstudent.getStudentcode(),
						tstudent.getHeadimg());
				Date date = new Date();
				String filepath = ImgUtil.usersimgpath + "/"
						+ tstudent.getStudentcode() + "/" + date.getTime()
						+ ".png";
				String fileurl = ConfigUtil.getProperty("default", "usersfile")
						+ tstudent.getStudentcode() + "/" + date.getTime()
						+ ".png";
				File file = new File(ImgUtil.usersimgpath + "/"
						+ tstudent.getHeadimg());
				ImgUtil.base64StringToImage(tstudent.getHeadimg(), filepath,
						file);
				tstudent.setHeadimg(fileurl);
			} else {
				student.setHeadimg(ConfigUtil.getProperty("default", "headimg"));
			}
			tstudent = (TStudent) getDao().create(tstudent);
			return tstudent;
		}
	}

	/**判断是否存在家长用户
	 * @author:wuqiwei
	 * @param @param fphone1
	 * @param @return
	 * @date:2016年6月21日下午5:40:13
	*/
	private List getParentDetail(String fphone1) {
		String sql = " select * from t_user where usercode = '"+fphone1+"' and usertype = 1";
		List  list = getDao().queryBySQL(sql);
		return list;
	}

	/**
	 * 添加学生信息及用户
	 * 
	 * @param tstudent
	 * @return
	 */
	public TStudent addStudent(TStudent tstudent) {
		// 添加学生信息
		TStudent student = getUserDetail(tstudent.getStudentcode(),
				tstudent.getSchoolcode());
		List list = getParentDetail(tstudent.getFphone1());
		// String usertype = student.getStudytype();
		if (student != null) {
			tstudent.setStudentcode("学生编码存在");
			tstudent.setType("1");
			return tstudent;
		}else if(list.size() > 0){
			tstudent.setStudentcode("家长编码存在,是否绑定到此家长");
			tstudent.setType("2");
			return tstudent;
		} else{
			if (tstudent.getHeadimg() != null
					&& tstudent.getHeadimg().length() > 0) {
				ImgUtil.remove(
						ImgUtil.studentsimgpath + "/"
								+ tstudent.getStudentcode(),
						tstudent.getHeadimg());
				Date date = new Date();
				String filepath = ImgUtil.studentsimgpath + "/"
						+ tstudent.getStudentcode() + "/" + date.getTime()
						+ ".png";
				String fileurl = ConfigUtil.getProperty("default",
						"studentsfile")
						+ tstudent.getStudentcode()
						+ "/"
						+ date.getTime() + ".png";
				File file = new File(ImgUtil.studentsimgpath + "/"
						+ tstudent.getHeadimg());
				ImgUtil.base64StringToImage(tstudent.getHeadimg(), filepath,
						file);
				tstudent.setHeadimg(fileurl);
			} else {
				tstudent.setHeadimg(ConfigUtil.getProperty("default",
						"stuheadimg"));
			}
			tstudent.setDel("1");
			tstudent = (TStudent) getDao().create(tstudent);
			// 添加终端
			if (tstudent.getTcard() != null) {
				TCard tc = tstudent.getTcard();
				tc = (TCard) getDao().create(tc);
				tstudent.setTcard(tc);
				TBdworkhour db = new TBdworkhour();
				db.setCardcode(tc.getImei());
				db.setWork(1);
				getDao().create(db);
				db = new TBdworkhour();
				db.setCardcode(tc.getImei());
				db.setWork(0);
				getDao().create(db);
				// 添加关联表
				TUserStudent tus = new TUserStudent();
				tus.setStudentcode(tstudent.getStudentcode());
				tus.setUsercode(tstudent.getFphone1());
				tus.setImei(tstudent.getTcard().getImei());
				getDao().create(tus);
			} else {
				// 添加关联表
				TUserStudent tus = new TUserStudent();
				tus.setStudentcode(tstudent.getStudentcode());
				tus.setUsercode(tstudent.getFphone1());
				tus.setImei("");
				getDao().create(tus);
				TCard tcard = getTcard(tstudent.getImei());// 去判断是否有这条记录
				if (tcard == null) {
					TCard tc = new TCard();
					tc.setStudentcode(tstudent.getStudentcode());
					tc.setCardcode(tstudent.getRfid());
					tc.setImei(tstudent.getImei());
					tc.setCellphone(tstudent.getCellphone());
					getDao().create(tc);
				}
			}
			// 添加用户信息
			UserService userService = new UserService();
			TUser tuser = new TUser();
			tuser.setUsercode(tstudent.getFphone1());
			tuser = userService.getUserDetail(tuser.getUsercode());
			if (tuser == null || tuser.getUsertype() == 2) {
				TUser tuserNew = new TUser();
				tuserNew.setUsercode(tstudent.getFphone1());
				tuserNew.setUsertype(1);
				tuserNew.setHeadimg(ConfigUtil
						.getProperty("default", "headimg"));
				tuserNew.setPassword(EncryptUtil.encryptMd5Password2(tstudent
						.getFphone1()));
				tuserNew.setUserkey(EncryptUtil.encryptMd5Password2(tuserNew
						.getUsercode() + tuserNew.getUsertype()));
				tuserNew.setAlias(tstudent.getFname1());
				tuserNew.setIslock(true);
				tuserNew.setLockdate((long) 0);
				tuserNew.setLocktype(1);
				tuserNew.setCellphone(tstudent.getFphone1());
				tuserNew.setAddress(tstudent.getFaddress1());
				tuserNew.setSchoolcode(tstudent.getSchoolcode());
				UserService us = new UserService();
				String mesid = us.regPushUser(
						tuserNew.getUsercode() + tuserNew.getUsertype(),
						tuserNew.getUsertype());
				tuserNew.setMessageid(mesid);
				tuserNew = (TUser) getDao().create(tuserNew);
				return tstudent;
			} else {
				return tstudent;
			}
		}
	}

	public TStudent bindStudent(TStudent tstudent){
		if (tstudent.getHeadimg() != null
				&& tstudent.getHeadimg().length() > 0) {
			ImgUtil.remove(
					ImgUtil.studentsimgpath + "/"
							+ tstudent.getStudentcode(),
					tstudent.getHeadimg());
			Date date = new Date();
			String filepath = ImgUtil.studentsimgpath + "/"
					+ tstudent.getStudentcode() + "/" + date.getTime()
					+ ".png";
			String fileurl = ConfigUtil.getProperty("default",
					"studentsfile")
					+ tstudent.getStudentcode()
					+ "/"
					+ date.getTime() + ".png";
			File file = new File(ImgUtil.studentsimgpath + "/"
					+ tstudent.getHeadimg());
			ImgUtil.base64StringToImage(tstudent.getHeadimg(), filepath,
					file);
			tstudent.setHeadimg(fileurl);
		} else {
			tstudent.setHeadimg(ConfigUtil.getProperty("default",
					"stuheadimg"));
		}
		tstudent.setDel("1");
		tstudent = (TStudent) getDao().create(tstudent);
		// 添加终端
		if (tstudent.getTcard() != null) {
			TCard tc = tstudent.getTcard();
			tc = (TCard) getDao().create(tc);
			tstudent.setTcard(tc);
			TBdworkhour db = new TBdworkhour();
			db.setCardcode(tc.getImei());
			db.setWork(1);
			getDao().create(db);
			db = new TBdworkhour();
			db.setCardcode(tc.getImei());
			db.setWork(0);
			getDao().create(db);
			// 添加关联表
			TUserStudent tus = new TUserStudent();
			tus.setStudentcode(tstudent.getStudentcode());
			tus.setUsercode(tstudent.getFphone1());
			tus.setImei(tstudent.getTcard().getImei());
			getDao().create(tus);
		} else {
			// 添加关联表
			TUserStudent tus = new TUserStudent();
			tus.setStudentcode(tstudent.getStudentcode());
			tus.setUsercode(tstudent.getFphone1());
			tus.setImei("");
			getDao().create(tus);
			TCard tcard = getTcard(tstudent.getImei());// 去判断是否有这条记录
			if (tcard == null) {
				TCard tc = new TCard();
				tc.setStudentcode(tstudent.getStudentcode());
				tc.setCardcode(tstudent.getRfid());
				tc.setImei(tstudent.getImei());
				getDao().create(tc);
			}
		}
		return tstudent;
	}
	/**
	 * 判断是否有这条记录
	 * 
	 * @author:wuqiwei
	 * @param @param imei
	 * @param @return
	 * @date:2016年1月29日下午1:58:49
	 */
	private TCard getTcard(String imei) {
		String hql = " FROM TCard  where imei = :imei";
		TCard tcard = new TCard();
		tcard.setImei(imei);
		TCard tc = (TCard) getDao().queryFirstByHQL(hql, tcard);
		return tc;
	}

	/**
	 * 判断数据库是否存在
	 * 
	 * @param usercode
	 * @return
	 */
	public TStudent getUserDetail(String studentcode, String schoolcode) {
		TStudent student = null;
		try {
			String hql = String.format("from TStudent where %1$s='%2$s'",
					"studentcode", studentcode, "schoolid", schoolcode);
			TStudent tstudent = new TStudent();
			tstudent.setStudentcode(studentcode);
			student = (TStudent) getDao().queryFirstByHQL(hql, tstudent);
			if (student == null) {
				return student;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return student;
	}

	/**
	 * 修改学生信息
	 * 
	 * @param tstudent
	 * @return
	 */
	public boolean updateInfo(TStudent tstudent) {
		TStudent student = getUserDetail(tstudent.getStudentcode(),
				tstudent.getSchoolcode());
		if (student != null) {
			for (Field f : tstudent.getClass().getDeclaredFields()) {
				f.setAccessible(true);
				try {
					if (f.get(tstudent) != null
							&& !f.getName()
									.equalsIgnoreCase("serialVersionUID")) {
						f.set(student, f.get(tstudent));
					}
				} catch (IllegalArgumentException e) {
					e.printStackTrace();
				} catch (IllegalAccessException e) {
					e.printStackTrace();
				}
			}
			if (tstudent.getHeadimg() != null
					&& tstudent.getHeadimg().length() > 0) {
				ImgUtil.remove(
						ImgUtil.usersimgpath + "/" + tstudent.getStudentcode(),
						tstudent.getHeadimg());
				Date date = new Date();
				String filepath = ImgUtil.usersimgpath + "/"
						+ tstudent.getStudentcode() + "/" + date.getTime()
						+ ".png";
				String fileurl = ConfigUtil.getProperty("default", "usersfile")
						+ tstudent.getStudentcode() + "/" + date.getTime()
						+ ".png";
				File file = new File(ImgUtil.usersimgpath + "/"
						+ tstudent.getHeadimg());
				ImgUtil.base64StringToImage(tstudent.getHeadimg(), filepath,
						file);
				student.setHeadimg(fileurl);
			}
			if (tstudent.getTcard() != null) {
				TCard tc = tstudent.getTcard();
				TCard tcard = getIsRepeatCard(tstudent.getStudentcode());
				if (tcard != null) {
					String sql = "DELETE tc,tus,tb FROM t_card tc,t_user_student tus,t_bdworkhour tb WHERE tc.studentcode = :studentcode AND tus.imei = tc.imei AND tb.cardcode = tc.imei";
					getDao().executeSQL(sql, tstudent);
				}
				tc = (TCard) getDao().create(tc);
				tstudent.setTcard(tc);
				TBdworkhour db = new TBdworkhour();
				db.setCardcode(tc.getImei());
				db.setWork(1);
				getDao().create(db);
				db = new TBdworkhour();
				db.setCardcode(tc.getImei());
				db.setWork(0);
				getDao().create(db);
				// 添加关联表
				TUserStudent tus = new TUserStudent();
				tus.setStudentcode(tstudent.getStudentcode());
				tus.setUsercode(tstudent.getFphone1());
				tus.setImei(tstudent.getTcard().getImei());
				getDao().create(tus);
			}
			tstudent = (TStudent) getDao().update(student);
			return true;
		} else {
			return false;
		}
	}

	public boolean askForLeaveByStudentCode(String studentcode) {
		return false;
	}

	/**
	 * 分页获取学生信息，按照班级，姓名搜索学生
	 * 
	 * @param classcode
	 * @param name
	 * @param currentpage
	 * @param pageSize
	 * @return map
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public Map getAllStudentsByPage(TStudent tstudent) {
		addPeriod();
		String classcodeSql = "";
		String classcodeHql = "";
		String nameSql = "";
		String nameHql = "";
		String tableName = "";
		if (tstudent.getDel() == null) {
			tstudent.setDel("1");
		}
		if (tstudent.getClasscode() != null
				&& tstudent.getClasscode().length() > 0) {
			if (tstudent.getClasscode().trim() != "") {
				classcodeSql = " and st.classcode = :classcode";
				classcodeHql = " and st.classcode = :classcode";
				tstudent.setClasscode(tstudent.getClasscode());
			}
		}
		if (tstudent.getName() != null && tstudent.getName().length() > 0) {
			nameSql = " and st.name like :name";
			nameHql = " and st.name like :name";
			tstudent.setName("%" + tstudent.getName() + "%");

		}
		if (tstudent.getRolecode() != null
				&& tstudent.getRolecode().length() > 0) {
			tableName = " StudentCard st,TDataRole dr,TClass tc";
		} else {
			tableName = " StudentCard st";
		}
		String hql = "select DISTINCT st FROM "+tableName+" where st.del=:del "
				+ classcodeHql + nameHql;
		if (tstudent.getSchoolcode() != null
				&& tstudent.getSchoolcode().length() > 0) {
			hql += " and st.schoolid = :schoolcode";
		}
		if (tstudent.getRolecode() != null
				&& tstudent.getRolecode().length() > 0) {
			tstudent.setRolecode(tstudent.getRolecode().replace(",", "^"));
			hql += " and st.classcode = dr.classcode and tc.classcode = dr.classcode and dr.rolecode in (:rolecode)";
		}
		if(tstudent.getType() != null && tstudent.getType().length() > 0){
			hql += " and tc.type = :type";
		}
		hql += " order by st.id";
//		String sql = "select count(*) from student_card st where st.del = :del and st.schoolid = :schoolcode "
//				+ classcodeSql + nameSql;
		List<StudentCard> list = null;
		if(tstudent.getCurrentpage() != null && tstudent.getCurrentpage() > 0 && tstudent.getPagesize() != null && tstudent.getPagesize() > 0){
			list = getDao().queryByHQLPage(hql, tstudent,tstudent.getCurrentpage(),tstudent.getPagesize());
		}else{
			list = getDao().queryByHQL(hql, tstudent);
		}
		
//		getDao().queryByHQLPage(hql, obj, currentpage, pagesize)
		List<Object[]> rs = new ArrayList<Object[]>();
		String keys = "";
		for (StudentCard sc : list) {
			String classcode = (String) addPeriodMap.get(sc.getClasscode());
			sc.setPeriodtype(classcode);
			keys = "";
			List<Object> values = new ArrayList<Object>();
			for (Field f : sc.getClass().getDeclaredFields()) {
				f.setAccessible(true);
				if (!f.getName().equalsIgnoreCase("serialVersionUID")) {
					keys = keys + f.getName() + ",";
					try {
						// 判断当是birdate或inschooldate的时候将格式转换
						if (f.getName().equalsIgnoreCase("birdate")
								|| f.getName().equalsIgnoreCase("inschooldate")) {
							values.add(DateUtil.getCustomFormatDate(
									Long.parseLong(String.valueOf(f.get(sc))),
									"yyyy-MM-dd"));// 格式转换
						} else {
							values.add(f.get(sc));
						}
					} catch (IllegalArgumentException e) {
					} catch (IllegalAccessException e) {
					}
				}

			}
			rs.add(values.toArray());
		}
		// 导出学生信息excel
		ResultSetToExcel rse = null;
		if (tstudent.getIsdownload() != null
				&& tstudent.getIsdownload().equalsIgnoreCase("true")) {
			rse = new ResultSetToExcel();
			rse.setColoumItem("学校编码,姓名,性别,出生日期,出生地行政区划代码,籍贯,民族,国籍/地区,身份证件类型,身份证件号,曾用名,身份证有效期,是否港澳台侨外,健康状况,血型,政治面貌,户口性质,户口所在地行政区划,现住址,通信地址,家庭地址,家庭联系电话,邮政编码,班号,入学年月,入学方式,就读方式,学籍辅号,班内学号,学生来源,特长,电子邮箱,主页地址,是否独生子女,是否受过学前教育,是否留守儿童,是否需要申请资助,是否享受一补,是否孤儿,是否烈士或优抚子女,是否进城务工人员随迁子女,残疾类型,是否由政府购买学位,上下学距离,上下学方式,是否需要乘坐校车,随班就读,成员1姓名,成员1关系,成员1说明,成员1现住址,成员1户口所在地行政区划,成员1联系电话,成员1是否监护人,成员1身份证件类型,成员1身份证件号,成员1民族,成员1工作单位,成员1职务,成员2姓名,成员2关系,成员2说明,成员2现住址,成员2户口所在地行政区划,成员2联系电话,成员2是否监护人,成员2身份证件类型,成员2身份证件号,成员2民族,成员2工作单位,成员2职务,班级编码,学生编码（设备号）,校车编码,删除状态,头像,手机号码,消息id,设备编码,手机号,IMEI,终端隐身时段,手机型号,备注,铃声,铃声swf,Sos报警设置,北斗工作时段,班,年级");
			rse.setRs(rs);
			rse.writeExcel();
		}
		int count = getDao().getCountByHqlPage(hql,tstudent);
		Map map = new HashMap();
		map.put("total", count);
		map.put("data", list);
		if (rse != null) {
			rse.setRs(null);
			map.put("remark", rse);
		}
		return map;
	}
	/**
	 * 添加学段
	 * @author:wuqiwei
	 * @param 
	 * @date:2016年6月17日下午5:25:46
	 */
	public void addPeriod(){
		String hql = " FROM TClass";
		List<TClass> list = getDao().queryByHQL(hql);
		for(int i = 0;i<list.size();i++){
			TClass cl = list.get(i);
			addPeriodMap.put(cl.getClasscode(),cl.getType());//将classcode作为key,type作为value
		}
	}
	public static void main(String[] args) {
		String s = StudentService.class.getResource(".").getPath();
		System.out.println(s);
		System.out.println(s.split("/")[1]);
	}

	/**
	 * 批量删除学生信息，假删除
	 * 
	 * @param studentcodes
	 * @return flag
	 */
	@SuppressWarnings("rawtypes")
	public boolean bachDeleteStudents(TStudent tstudent) {
		boolean flag = true;
		String values = "";
		List list = tstudent.getStudentcodes();
		for (int i = 0; i < list.size(); i++) {
			values += "'" + list.get(i) + "',";
		}
		values = values.substring(0, values.length() - 1);
		String sql = "update t_student set del='0' where studentcode in ("
				+ values + ")";
		int res = getDao().executeSQL(sql);
		List<TUserStudent> li = getIsUserStudent(values);
		if (li != null) {
			String sql2 = "delete from t_user_student where studentcode in ("
					+ values + ")";
			getDao().executeSQL(sql2);
		}
		if (res == -1) {
			flag = false;
		}
		return flag;
	}

	public boolean unLockStudent(TStudent tstudent) {
		boolean flag = true;
		String sql = "update t_student set del='1' where studentcode = :studentcode";
		int res = getDao().executeSQL(sql, tstudent);
		if (tstudent.getImei() == null || tstudent.getImei() == "") {
			tstudent.setImei("");
		}
		String sql2 = "insert into t_user_student (id,usercode,studentcode,imei) values (null,:fphone1,:studentcode,:imei)";
		getDao().executeSQL(sql2, tstudent);
		if (res == -1) {
			flag = false;
		}
		return flag;
	}

	// 用户学生中间表判断
	@SuppressWarnings("unchecked")
	public List<TUserStudent> getIsUserStudent(String studentcodes) {
		String sql = "SELECT * FROM t_user_student WHERE studentcode in (:studentcodes)";
		TUserStudent tUserStudent = new TUserStudent();
		tUserStudent.setStudentcode(studentcodes.replace(",", "^"));
		List<TUserStudent> list = getDao().queryBySQL(sql, tUserStudent);
		return list;
	}

	// 终端表判断
	public TCard getIsRepeatCard(String studentcode) {
		TCard tcard = null;
		try {
			String hql = String.format("from TCard where %1$s='%2$s'",
					"studentcode", studentcode);
			TCard card = new TCard();
			card.setStudentcode(studentcode);
			tcard = (TCard) getDao().queryFirstByHQL(hql);
			if (tcard == null) {
				return tcard;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return tcard;
	}

	/**
	 * 删除学生信息 关联的信息全部删除
	 * 
	 * @author:wuqiwei
	 * @param @param studentcode
	 * @param @param imei
	 * @param @return
	 * @date:2016年6月6日下午5:17:14
	 */
	@SuppressWarnings("rawtypes")
	public boolean deleteInfo(String studentcode, String imei) {
		boolean flag = false;
		String[] table = new String[] { "t_warn_sos", "t_user_student",
				"t_fence", "t_attendance", "t_examinationresult", "t_leave",
				"t_card", "t_phonebook", "t_sosphone", "t_familyphone",
				"t_student" };
		// 去查询 这个家长下面 是否还绑定其它孩子
		String qsql = "SELECT * FROM t_user_student tus WHERE tus.studentcode NOT IN('"
				+ studentcode
				+ "') AND tus.usercode IN (SELECT DISTINCT usercode FROM t_user_student WHERE studentcode = '"
				+ studentcode + "')";
		List list = getDao().queryBySQL(qsql);
		if (list.size() == 0) {// 如果没绑定就删除
			String dsql = "SELECT DISTINCT usercode FROM t_user_student WHERE studentcode = '"
					+ studentcode + "'";
			List dlist = getDao().queryBySQL(dsql);
			if (dlist.size() != 0) {
				String usercode = String.valueOf(dlist.get(0));
				String desql = "delete from t_user where usercode = '"
						+ usercode + "'";
				int a = getDao().executeSQL(desql);
				if (a > 0) {
					flag = true;
				}
			}
		}
		String sql = "delete from ";
		TStudent tstudent = new TStudent();
		for (int i = 0; i < table.length; i++) {
			String sql2 = sql + table[i] + " where studentcode='" + studentcode
					+ "'";
			tstudent.setStudentcode(studentcode);
			tstudent.setImei(imei);
			if (table[i] == "t_phonebook") {
				sql2 = sql + table[i] + " where imei='" + imei + "'";
			} else if (table[i] == "t_sosphone") {
				sql2 = sql + table[i] + " where imei='" + imei + "'";
			} else if (table[i] == "t_familyphone") {
				sql2 = sql + table[i] + " where imei='" + imei + "'";
			} else if (table[i] == "t_warn_sos") {
				sql2 = sql + table[i] + " where imei='" + imei + "'";
			} else if (table[i] == "t_fence") {
				sql2 = sql + table[i] + " where studentcode='" + studentcode
						+ "'";
			} else if (table[i] == "t_attendance") {
				sql2 = sql + table[i] + " where studentcode='" + studentcode
						+ "'";
			} else if (table[i] == "t_examinationresult") {
				sql2 = sql + table[i] + " where studentcode='" + studentcode
						+ "'";
			} else if (table[i] == "t_leave") {
				sql2 = sql + table[i] + " where studentcode='" + studentcode
						+ "'";
			} else if (table[i] == "t_card") {
				sql2 = sql + table[i] + " where studentcode='" + studentcode
						+ "'";
			} else if (table[i] == "t_phonebook") {
				sql2 = sql + table[i] + " where studentcode='" + studentcode
						+ "'";
			} else if (table[i] == "t_sosphone") {
				sql2 = sql + table[i] + " where imei='" + imei + "'";
			} else if (table[i] == "t_familyphone") {
				sql2 = sql + table[i] + " where imei='" + imei + "'";
			} else if (table[i] == "t_student") {
				sql2 = sql + table[i] + " where studentcode='" + studentcode
						+ "'";
			}
			table[i] = sql2;
			sql2 = "";
		}
		if (getDao().deleteSQL(table) > 0) {
			flag = true;
		}
		return flag;
	}

}
